home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Util / M-Mc / MacVCR+ Folder / decode_routine.c next >
Encoding:
C/C++ Source or Header  |  1993-04-11  |  14.6 KB  |  766 lines  |  [TEXT/ttxt]

  1. #include <stdio.h>
  2.  
  3. #define        KEY001    (68150631)
  4. #define        INVALID    (-987)
  5.  
  6. /***************************************************************
  7.  * Modified:    Kent Anthony Behrends    01-Apr-1993    ver 01-000
  8.  *                1. Add macro STANDALONE, if defined, then this
  9.  *                   is a 'main' routine and can be compiled and
  10.  *                   linked to make a standalone program.
  11.  *                   Otherwise it can be called as a function.
  12.  *         2. Defined functions as static.
  13.  ***************************************************************/
  14. /*
  15.  * define STANDALONE if not embedded. 
  16.  */
  17. /* #define STANDALONE
  18.  * #include <console.h>         Needed for Macintosh console i/o
  19.  */
  20.  
  21.  
  22. /* function that performs initial scrambling */
  23. static int    mixup(x, y)
  24.     int    x, y;
  25. {
  26.     int    i, j, k, sum;
  27.  
  28.     int    a[12], b[12], out[12] ;
  29.  
  30.     /* get the digits of x into a[] */
  31.     j = x ;
  32.     for(i=0; i<9; i++)
  33.     {
  34.         k = j % 10;
  35.         a[i] = k;
  36.         j = (j - k) / 10 ;
  37.     }
  38.  
  39.     /* get the digits of y into b[] */
  40.     j = y ;
  41.     for(i=0; i<9; i++)
  42.     {
  43.         k = j % 10;
  44.         b[i] = k;
  45.         j = (j - k) / 10 ;
  46.         out[i] = 0;
  47.     }
  48.  
  49.  
  50.     for(i=0; i<=8; i++)
  51.     {
  52.         for(j=0; j<=8; j++)
  53.         {
  54.             out[i+j] += (b[j] * a[i]) ;
  55.         }
  56.     }
  57.  
  58.     j = 1;
  59.     sum = 0;
  60.     for(i=0; i<=8; i++)
  61.     {
  62.         sum += j * (out[i] % 10);
  63.         j = j * 10 ;
  64.     }
  65.     return( sum ) ;
  66. }
  67.  
  68. /* first function */
  69. static int    f1(inval)
  70.     int    inval ;
  71. {
  72.     int    ndigits, hashval ;
  73.     int    pwr ;
  74.  
  75.  
  76.     ndigits = 0;
  77.     pwr = 1;
  78.     while(inval >= pwr) { ndigits++; pwr *= 10; }
  79.     if(ndigits > 8) printf("\nPANIC: %d has %d digits\n", inval, ndigits);
  80.     pwr = pwr / 10 ;
  81.  
  82.     hashval = inval;
  83. again:    hashval = mixup(hashval, KEY001) % (pwr * 10) ;
  84.     if(hashval < pwr) goto again ;
  85.  
  86.     return(hashval);
  87. }
  88.  
  89.  
  90. /* the 512-entry tables of starting time and pgm duration */
  91. static void    lookup(i, outtime, outdur)
  92.     int    i, *outtime, *outdur ;
  93. {
  94.     static    int    start[480], leng[480] ;
  95.     static    int    initializer = 0;
  96.  
  97.     int    j, s;
  98.  
  99.     if(initializer == 0) {
  100.     initializer = 1;
  101.  
  102.     for(j=0; j<512; j++) { start[j] = leng[j] = INVALID; }
  103.  
  104.     leng[0]   =  30 ;
  105.     leng[100] = 120 ;
  106.     leng[101] =  90 ;
  107.     leng[102] = 120 ;
  108.     leng[103] = 120 ;
  109.     leng[104] =  90 ;
  110.     leng[105] =  90 ;
  111.     leng[106] =  30 ;
  112.     leng[107] =  30 ;
  113.     leng[108] = 120 ;
  114.     leng[109] =  90 ;
  115.     leng[10]  =  30 ;
  116.     leng[110] =  90 ;
  117.     leng[111] =  30 ;
  118.     leng[112] =  90 ;
  119.     leng[113] =  30 ;
  120.     leng[114] =  30 ;
  121.     leng[115] = 120 ;
  122.     leng[116] =  30 ;
  123.     leng[117] = 120 ;
  124.     leng[118] = 120 ;
  125.     leng[119] =  30 ;
  126.     leng[11]  =  30 ;
  127.     leng[120] =  90 ;
  128.     leng[121] =  60 ;
  129.     leng[122] =  60 ;
  130.     leng[123] =  60 ;
  131.     leng[124] = 120 ;
  132.     leng[125] =  90 ;
  133.     leng[126] =  60 ;
  134.     leng[127] =  60 ;
  135.     leng[128] =  90 ;
  136.     leng[129] = 120 ;
  137.     leng[12]  =  30 ;
  138.     leng[130] = 120 ;
  139.     leng[131] =  90 ;
  140.     leng[132] =  60 ;
  141.     leng[133] =  60 ;
  142.     leng[134] = 120 ;
  143.     leng[135] =  90 ;
  144.     leng[136] =  90 ;
  145.     leng[137] = 120 ;
  146.     leng[138] = 120 ;
  147.     leng[139] =  60 ;
  148.     leng[13]  = 120 ;
  149.     leng[140] =  60 ;
  150.     leng[141] =  90 ;
  151.     leng[142] =  90 ;
  152.     leng[143] = 120 ;
  153.     leng[144] =  90 ;
  154.     leng[145] = 120 ;
  155.     leng[146] =  90 ;
  156.     leng[147] = 120 ;
  157.     leng[148] = 120 ;
  158.     leng[149] =  90 ;
  159.     leng[14]  =  30 ;
  160.     leng[150] = 120 ;
  161.     leng[151] =  90 ;
  162.     leng[152] =  90 ;
  163.     leng[153] =  90 ;
  164.     leng[154] =  60 ;
  165.     leng[155] =  60 ;
  166.     leng[156] = 120 ;
  167.     leng[157] =  60 ;
  168.     leng[158] =  60 ;
  169.     leng[159] =  60 ;
  170.     leng[15]  =  30 ;
  171.     leng[160] = 120 ;
  172.     leng[161] =  60 ;
  173.     leng[162] =  90 ;
  174.     leng[163] =  90 ;
  175.     leng[164] =  60 ;
  176.     leng[165] =  90 ;
  177.     leng[166] =  90 ;
  178.     leng[167] =  60 ;
  179.     leng[168] =  90 ;
  180.     leng[169] = 120 ;
  181.     leng[16]  = 120 ;
  182.     leng[170] =  60 ;
  183.     leng[171] = 120 ;
  184.     leng[172] =  60 ;
  185.     leng[173] =  60 ;
  186.     leng[174] = 120 ;
  187.     leng[175] =  90 ;
  188.     leng[176] =  60 ;
  189.     leng[177] = 120 ;
  190.     leng[178] =  60 ;
  191.     leng[179] =  60 ;
  192.     leng[17]  = 120 ;
  193.     leng[180] =  60 ;
  194.     leng[181] =  90 ;
  195.     leng[182] =  60 ;
  196.     leng[183] = 120 ;
  197.     leng[184] =  60 ;
  198.     leng[185] =  60 ;
  199.     leng[186] =  90 ;
  200.     leng[187] =  60 ;
  201.     leng[188] =  90 ;
  202.     leng[189] = 120 ;
  203.     leng[18]  =  60 ;
  204.     leng[190] =  90 ;
  205.     leng[191] =  90 ;
  206.     leng[19]  = 120 ;
  207.     leng[1]   =  30 ;
  208.     leng[20]  =  60 ;
  209.     leng[21]  =  60 ;
  210.     leng[22]  =  60 ;
  211.     leng[23]  = 120 ;
  212.     leng[24]  =  60 ;
  213.     leng[25]  = 120 ;
  214.     leng[26]  =  30 ;
  215.     leng[27]  =  30 ;
  216.     leng[28]  =  30 ;
  217.     leng[29]  =  60 ;
  218.     leng[2]   =  30 ;
  219.     leng[30]  =  90 ;
  220.     leng[31]  =  30 ;
  221.     leng[32]  =  30 ;
  222.     leng[33]  =  30 ;
  223.     leng[34]  =  30 ;
  224.     leng[35]  =  60 ;
  225.     leng[36]  =  30 ;
  226.     leng[37]  =  60 ;
  227.     leng[38]  = 120 ;
  228.     leng[39]  =  60 ;
  229.     leng[3]   =  30 ;
  230.     leng[40]  =  30 ;
  231.     leng[41]  =  30 ;
  232.     leng[42]  =  30 ;
  233.     leng[43]  =  30 ;
  234.     leng[44]  = 120 ;
  235.     leng[45]  =  30 ;
  236.     leng[46]  =  30 ;
  237.     leng[47]  =  30 ;
  238.     leng[48]  = 120 ;
  239.     leng[49]  =  30 ;
  240.     leng[4]   =  30 ;
  241.     leng[50]  =  60 ;
  242.     leng[51]  =  60 ;
  243.     leng[52]  =  30 ;
  244.     leng[53]  =  30 ;
  245.     leng[54]  = 120 ;
  246.     leng[55]  =  60 ;
  247.     leng[56]  =  60 ;
  248.     leng[57]  =  30 ;
  249.     leng[58]  = 120 ;
  250.     leng[59]  =  30 ;
  251.     leng[5]   =  30 ;
  252.     leng[60]  = 120 ;
  253.     leng[61]  = 120 ;
  254.     leng[62]  = 120 ;
  255.     leng[63]  =  30 ;
  256.     leng[64]  =  90 ;
  257.     leng[65]  =  30 ;
  258.     leng[66]  =  30 ;
  259.     leng[67]  =  30 ;
  260.     leng[68]  = 120 ;
  261.     leng[69]  =  90 ;
  262.     leng[6]   =  30 ;
  263.     leng[70]  =  90 ;
  264.     leng[71]  =  60 ;
  265.     leng[72]  =  90 ;
  266.     leng[73]  =  90 ;
  267.     leng[74]  =  90 ;
  268.     leng[75]  =  90 ;
  269.     leng[76]  =  90 ;
  270.     leng[77]  =  60 ;
  271.     leng[78]  =  90 ;
  272.     leng[79]  =  30 ;
  273.     leng[7]   =  30 ;
  274.     leng[80]  = 120 ;
  275.     leng[81]  =  60 ;
  276.     leng[82]  =  90 ;
  277.     leng[83]  = 120 ;
  278.     leng[84]  =  60 ;
  279.     leng[85]  =  60 ;
  280.     leng[86]  = 120 ;
  281.     leng[87]  =  30 ;
  282.     leng[88]  =  90 ;
  283.     leng[89]  = 120 ;
  284.     leng[8]   =  30 ;
  285.     leng[90]  = 120 ;
  286.     leng[91]  =  90 ;
  287.     leng[92]  =  90 ;
  288.     leng[93]  =  90 ;
  289.     leng[94]  =  90 ;
  290.     leng[95]  = 120 ;
  291.     leng[96]  =  60 ;
  292.     leng[97]  = 120 ;
  293.     leng[98]  =  90 ;
  294.     leng[99]  =  30 ;
  295.     leng[9]   =  60 ;
  296.     start[0]   = 1830 ;
  297.     start[100] =  330 ;
  298.     start[101] = 1500 ;
  299.     start[102] = 1500 ;
  300.     start[103] = 2300 ;
  301.     start[104] = 1900 ;
  302.     start[105] =  800 ;
  303.     start[106] =  430 ;
  304.     start[107] =  300 ;
  305.     start[108] = 1330 ;
  306.     start[109] = 1000 ;
  307.     start[10]  = 1400 ;
  308.     start[110] =  700 ;
  309.     start[111] =  100 ;
  310.     start[112] = 2330 ;
  311.     start[113] =  330 ;
  312.     start[114] =  200 ;
  313.     start[115] = 2230 ;
  314.     start[116] =  400 ;
  315.     start[117] =  600 ;
  316.     start[118] =  400 ;
  317.     start[119] =  230 ;
  318.     start[11]  = 2030 ;
  319.     start[120] =  630 ;
  320.     start[121] =   30 ;
  321.     start[122] = 2230 ;
  322.     start[123] =  100 ;
  323.     start[124] =   30 ;
  324.     start[125] = 2300 ;
  325.     start[126] = 1630 ;
  326.     start[127] =  830 ;
  327.     start[128] =    0 ;
  328.     start[129] = 1930 ;
  329.     start[12]  = 1700 ;
  330.     start[130] =  930 ;
  331.     start[131] = 2030 ;
  332.     start[132] =  500 ;
  333.     start[133] = 1730 ;
  334.     start[134] =  200 ;
  335.     start[135] = 1930 ;
  336.     start[136] =  930 ;
  337.     start[137] = 1730 ;
  338.     start[138] =  630 ;
  339.     start[139] = 1830 ;
  340.     start[13]  = 1600 ;
  341.     start[140] = 1430 ;
  342.     start[141] = 1130 ;
  343.     start[142] =   30 ;
  344.     start[143] =  830 ;
  345.     start[144] = 1030 ;
  346.     start[145] = 1430 ;
  347.     start[146] =  100 ;
  348.     start[147] =  730 ;
  349.     start[148] = 2030 ;
  350.     start[149] =  300 ;
  351.     start[14]  = 2000 ;
  352.     start[150] =  300 ;
  353.     start[151] = 1330 ;
  354.     start[152] = 1230 ;
  355.     start[153] =  230 ;
  356.     start[154] = 2130 ;
  357.     start[155] = 1130 ;
  358.     start[156] = 1830 ;
  359.     start[157] =  630 ;
  360.     start[158] =  530 ;
  361.     start[159] =  200 ;
  362.     start[15]  = 1500 ;
  363.     start[160] = 1530 ;
  364.     start[161] =  730 ;
  365.     start[162] =  600 ;
  366.     start[163] = 1730 ;
  367.     start[164] =  400 ;
  368.     start[165] =  730 ;
  369.     start[166] =  430 ;
  370.     start[167] =  430 ;
  371.     start[168] =  130 ;
  372.     start[169] = 1230 ;
  373.     start[16]  = 2000 ;
  374.     start[170] =  130 ;
  375.     start[171] =  230 ;
  376.     start[172] = 1930 ;
  377.     start[173] =  300 ;
  378.     start[174] = 1030 ;
  379.     start[175] =  200 ;
  380.     start[176] =  330 ;
  381.     start[177] =  500 ;
  382.     start[178] =  930 ;
  383.     start[179] =  230 ;
  384.     start[17]  = 2100 ;
  385.     start[180] = 2030 ;
  386.     start[181] =  400 ;
  387.     start[182] = 1530 ;
  388.     start[183] =  430 ;
  389.     start[184] = 1330 ;
  390.     start[185] = 1230 ;
  391.     start[186] =  330 ;
  392.     start[187] = 1030 ;
  393.     start[188] =  500 ;
  394.     start[189] =  530 ;
  395.     start[18]  = 2000 ;
  396.     start[190] =  530 ;
  397.     start[191] = 1100 ;
  398.     start[19]  = 1800 ;
  399.     start[1]   = 1600 ;
  400.     start[20]  = 1900 ;
  401.     start[21]  = 2200 ;
  402.     start[22]  = 2100 ;
  403.     start[23]  = 1400 ;
  404.     start[24]  = 1500 ;
  405.     start[25]  = 2200 ;
  406.     start[26]  = 1130 ;
  407.     start[27]  = 1100 ;
  408.     start[28]  = 2300 ;
  409.     start[29]  = 1600 ;
  410.     start[2]   = 1930 ;
  411.     start[30]  = 2100 ;
  412.     start[31]  = 2100 ;
  413.     start[32]  = 1230 ;
  414.     start[33]  = 1330 ;
  415.     start[34]  =  930 ;
  416.     start[35]  = 1300 ;
  417.     start[36]  = 2130 ;
  418.     start[37]  = 1200 ;
  419.     start[38]  = 1000 ;
  420.     start[39]  = 1800 ;
  421.     start[3]   = 1630 ;
  422.     start[40]  = 2200 ;
  423.     start[41]  = 1200 ;
  424.     start[42]  =  800 ;
  425.     start[43]  =  830 ;
  426.     start[44]  = 1700 ;
  427.     start[45]  =  900 ;
  428.     start[46]  = 2230 ;
  429.     start[47]  = 1030 ;
  430.     start[48]  = 1900 ;
  431.     start[49]  =  730 ;
  432.     start[4]   = 1530 ;
  433.     start[50]  = 2300 ;
  434.     start[51]  = 1000 ;
  435.     start[52]  =  700 ;
  436.     start[53]  = 1300 ;
  437.     start[54]  =  700 ;
  438.     start[55]  = 1100 ;
  439.     start[56]  = 1400 ;
  440.     start[57]  = 1000 ;
  441.     start[58]  =  800 ;
  442.     start[59]  = 2330 ;
  443.     start[5]   = 1730 ;
  444.     start[60]  = 1300 ;
  445.     start[61]  = 1200 ;
  446.     start[62]  =  900 ;
  447.     start[63]  =  630 ;
  448.     start[64]  = 1800 ;
  449.     start[65]  =  600 ;
  450.     start[66]  =  530 ;
  451.     start[67]  =    0 ;
  452.     start[68]  = 2330 ;
  453.     start[69]  = 2200 ;
  454.     start[6]   = 1800 ;
  455.     start[70]  = 1300 ;
  456.     start[71]  =  900 ;
  457.     start[72]  = 1630 ;
  458.     start[73]  = 1600 ;
  459.     start[74]  = 1430 ;
  460.     start[75]  = 2000 ;
  461.     start[76]  = 1830 ;
  462.     start[77]  =  600 ;
  463.     start[78]  = 1200 ;
  464.     start[79]  =   30 ;
  465.     start[7]   = 1430 ;
  466.     start[80]  =  130 ;
  467.     start[81]  =    0 ;
  468.     start[82]  = 1700 ;
  469.     start[83]  =    0 ;
  470.     start[84]  =  800 ;
  471.     start[85]  =  700 ;
  472.     start[86]  = 2130 ;
  473.     start[87]  =  500 ;
  474.     start[88]  = 1530 ;
  475.     start[89]  = 1130 ;
  476.     start[8]   = 1900 ;
  477.     start[90]  = 1100 ;
  478.     start[91]  =  830 ;
  479.     start[92]  = 2230 ;
  480.     start[93]  =  900 ;
  481.     start[94]  = 2130 ;
  482.     start[95]  = 1630 ;
  483.     start[96]  = 2330 ;
  484.     start[97]  =  100 ;
  485.     start[98]  = 1400 ;
  486.     start[99]  =  130 ;
  487.     start[9]   = 1700 ;
  488.  
  489.  
  490.     s = 2330;
  491.     for(j=192; j<240; j++)
  492.     { start[j] = s; leng[j] = 150; if(0==(j%2)) s-=30; else s-=70; }
  493.  
  494.     s = 2330;
  495.     for(j=240; j<288; j++)
  496.     { start[j] = s; leng[j] = 180; if(0==(j%2)) s-=30; else s-=70; }
  497.  
  498.     s = 2330;
  499.     for(j=288; j<336; j++)
  500.     { start[j] = s; leng[j] = 210; if(0==(j%2)) s-=30; else s-=70; }
  501.  
  502.     s = 2330;
  503.     for(j=336; j<384; j++)
  504.     { start[j] = s; leng[j] = 240; if(0==(j%2)) s-=30; else s-=70; }
  505.  
  506.     s = 2330;
  507.     for(j=384; j<432; j++)
  508.     { start[j] = s; leng[j] = 270; if(0==(j%2)) s-=30; else s-=70; }
  509.  
  510.     s = 2330;
  511.     for(j=432; j<480; j++)
  512.     { start[j] = s; leng[j] = 300; if(0==(j%2)) s-=30; else s-=70; }
  513.  
  514.     } /* end of initializer block */
  515.  
  516.  
  517.  
  518.     if((i >= 480) || (i < 0))
  519.         printf("\nPANIC, Illegal table index %d\n", i);
  520.  
  521.     fflush(stdout);
  522.     *outtime = (start[i]) ;
  523.     *outdur = (leng[i]) ;
  524.  
  525.     if( (*outtime == INVALID) || (*outdur == INVALID) )
  526.     {
  527.         printf("oops, I dont have an entry for index %d\n", i);
  528.         fflush(stdout);
  529.         *outtime = 0;
  530.         *outdur = 0;
  531.     }
  532. }
  533.  
  534. static int    map_top(day, year, top, digits)
  535.     int    day, year, top, digits ;
  536. {
  537.     int    d2, d1, d0, y, poot ;
  538.     int    n2, n1, n0, f3, f2, f1, f0;
  539.  
  540.     y = year % 16 ;
  541.     d2 = top / 100 ;
  542.     d1 = (top % 100) / 10 ;
  543.     d0 = top % 10 ;
  544.  
  545.     f0 = 1;
  546.     f1 = (y + 1) % 10;
  547.     f2 = ( ((y+1)*(y+2)) / 2 ) % 10 ;
  548.     f3 = ( ((y+1)*(y+2)*(y+3)) / 6 ) % 10 ;
  549.  
  550.  
  551.     if(digits == 1)
  552.     {
  553.         n0 = ( (d0*f0) + (day*f1) ) % 10 ;
  554.         n1 = 0;
  555.         n2 = 0;
  556.     }
  557.  
  558.     if(digits == 2)
  559.     {
  560.         n0 = ( (d0*f0) + (d1*f1) + (day*f2) ) % 10 ;
  561.         n1 = ( (d1*f0) + (day*f1) ) % 10 ;
  562.         n2 = 0;
  563.     }
  564.  
  565.     if(digits == 3)
  566.     {
  567.         n0 = ( (d0*f0) + (d1*f1) + (d2*f2) + (day*f3) ) % 10 ;
  568.         n1 = ( (d1*f0) + (d2*f1) + (day*f2) ) % 10 ;
  569.         n2 = ( (d2*f0) + (day*f1) ) % 10 ;
  570.     }
  571.  
  572.  
  573.     poot =  (100*n2) + (10*n1) + n0 ;
  574.  
  575.     return( poot );
  576. }
  577.  
  578. static void    offset(day, year, top, ofout, topout)
  579.     int    day, year, top ;
  580.     int    *ofout, *topout ;
  581. {
  582.     int    i, t, tx, off, digits, burp;
  583.     int    pwr ;
  584.  
  585.     pwr = 1 ; digits = 0;
  586.     while(top >= pwr) { digits++; pwr *= 10; }
  587.     pwr = pwr / 10 ;
  588.  
  589.     t = tx = top ;
  590.     off = 0;
  591.     while(tx > 0) { off += (tx % 10);   tx /= 10; }
  592.  
  593. again:
  594.     for(i=0; i<=(year%16); i++)
  595.         {
  596.         burp = ( (map_top(day, i, t, digits)) % 10 ) ;
  597.         off += burp ;
  598.         }
  599.  
  600.     t = map_top(day, year, t, digits) ;
  601.     if(t < pwr) goto again ;
  602.  
  603.  
  604.     *ofout = (off % 32) ;
  605.     *topout = (t) ;
  606. }
  607.  
  608. static void    bit_shuffle(t8c5, t2c1, tval, cval)
  609.     int    t8c5, t2c1;
  610.     int    *tval, *cval ;
  611. {
  612.     int    tt, cc, b;
  613.  
  614.     tt = 0 ;
  615.     cc = 0 ;
  616.  
  617.     /* get t8 thru t3 */
  618.     b = 0x00000001 & (t8c5 >> 9) ;
  619.     tt += (b << 8);
  620.  
  621.     b = 0x00000001 & (t8c5 >> 7) ;
  622.     tt += (b << 7);
  623.  
  624.     b = 0x00000001 & (t8c5 >> 5) ;
  625.     tt += (b << 6);
  626.  
  627.     b = 0x00000001 & (t8c5 >> 4) ;
  628.     tt += (b << 5);
  629.  
  630.     b = 0x00000001 & (t8c5 >> 3) ;
  631.     tt += (b << 4);
  632.  
  633.     b = 0x00000001 & t8c5 ;
  634.     tt += (b << 3);
  635.  
  636.  
  637.     /* get c5 thru c2 */
  638.     b = 0x00000001 & (t8c5 >> 8) ;
  639.     cc += (b << 5);
  640.  
  641.     b = 0x00000001 & (t8c5 >> 6) ;
  642.     cc += (b << 4);
  643.  
  644.     b = 0x00000001 & (t8c5 >> 2) ;
  645.     cc += (b << 3);
  646.  
  647.     b = 0x00000001 & (t8c5 >> 1) ;
  648.     cc += (b << 2) ;
  649.  
  650.  
  651.     /* get t2 thru t0 */
  652.     b = 0x00000001 & (t2c1 >> 4) ;
  653.     tt += (b << 2);
  654.  
  655.     b = 0x00000001 & (t2c1 >> 2) ;
  656.     tt += (b << 1);
  657.  
  658.     b = 0x00000001 & t2c1 ;
  659.     tt += b;
  660.  
  661.  
  662.     /* get c1 thru c0 */
  663.     b = 0x00000001 & (t2c1 >> 3) ;
  664.     cc += (b << 1);
  665.  
  666.     b = 0x00000001 & (t2c1 >> 1) ;
  667.     cc += b ;
  668.  
  669.     *tval = tt;
  670.     *cval = cc;
  671. }
  672.  
  673. #ifdef STANDALONE
  674. /*
  675.  *---------- Standalone --------------------------------------------------------
  676.  */
  677.  
  678. main(argc, argv)
  679.     int    argc;
  680.     char    *argv[];
  681. {
  682.     int    newspaper ;
  683.     int    s1_out, bot3, top5, quo, rem ;
  684.     int    s5_out, mtout, ofout, tval, cval ;
  685.     int    date_today, month_today, year_today ;
  686.     int    day_out, channel_out;
  687.     int    starttime_out, duration_out ;
  688.  
  689.  
  690.  
  691.     if(argc != 5) goto upchuck;
  692.  
  693.  
  694. clean:
  695.  
  696.     month_today = atoi(argv[1]);
  697.     date_today = atoi(argv[2]);
  698.     year_today = atoi(argv[3]);
  699.     newspaper = atoi(argv[4]);
  700.  
  701. #else
  702. /*
  703.  *---------- Embedded --------------------------------------------------------
  704.  */
  705. void decode_main(int month_today, int date_today, int year_today, int newspaper,
  706.                 int *channel_ret, int *starttime_ret, int *duration_ret)
  707. {
  708.     int    s1_out, bot3, top5, quo, rem ;
  709.     int    s5_out, mtout, ofout, tval, cval ;
  710.     int    day_out, channel_out;
  711.     int    starttime_out, duration_out ;
  712.  
  713. #endif /* STANDALONE */
  714.  
  715.     year_today = year_today % 100 ;
  716.  
  717.  
  718.     if( (month_today>12) || (month_today<1) || (date_today<1) || (date_today>31) )
  719.     { printf("Invalid date\n"); goto upchuck; }
  720.  
  721.     if((newspaper < 1) || (newspaper > 999999))
  722.     { printf("Sorry, I cant process that code value\n  I can only do codes with 6 digits or fewer\n"); goto upchuck; }
  723.  
  724.  
  725.  
  726.  
  727.     ofout = INVALID ;
  728.     mtout = INVALID ;
  729.  
  730.     s1_out = f1(newspaper); 
  731.     bot3 = s1_out % 1000;
  732.     top5 = s1_out / 1000;
  733.     quo = (bot3 - 1) / 32 ;
  734.     rem = (bot3 - 1) % 32 ;
  735.     day_out = quo + 1;
  736.  
  737.     if(newspaper >= 1000)
  738.         offset(day_out, year_today, top5, (&ofout), (&mtout)) ;
  739.     else { mtout = 0; ofout = 0; }
  740.  
  741.     s5_out = (rem + (day_out*(month_today+1)) + ofout) % 32 ;
  742.  
  743.  
  744.     bit_shuffle(mtout, s5_out, &tval, &cval);
  745.     channel_out = cval + 1;
  746.     lookup(tval, (&starttime_out), (&duration_out));
  747.  
  748. #ifdef STANDALONE
  749.  
  750.     printf("Code= %6d    %2d  %2d  %2d   Mapped_channel= %2d  Start_time= %4d  Length= %3d\n",
  751.         newspaper, month_today, day_out, year_today, channel_out, starttime_out, duration_out);
  752.  
  753. #else
  754.  
  755.     *channel_ret   = channel_out;
  756.     *starttime_ret = starttime_out;
  757.     *duration_ret  = duration_out;
  758.     return;
  759.     
  760. #endif /* STANDALONE */
  761.  
  762. upchuck:
  763.     printf("Usage: decode todays_month  todays_day  todays_year   Code_value_in_newspaper\n");
  764.     exit(-1) ;
  765. }
  766.